/**
 * Created by Administrator on 2017/12/19.
 */
import cookie from "js-cookie";
import { Toast } from 'antd-mobile';
import { routerRedux } from 'dva/router';
import { transferlists } from '../../services/organization';

export default {

  namespace: 'historys',

  state: {
    Lists:[],
  },
  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(({pathname, query}) => {
        if(pathname === '/work/zzgx/applyhistory') {
          dispatch({
            type:'fetch',
          })
        }
      })
    }
  },

  effects: {
    *fetch({payload}, { call, put, select }) {
      let newsObject = sessionStorage.getItem('userdata');
      newsObject = JSON.parse(newsObject);
      if(!newsObject){
        //跳转到列表页
        yield put(routerRedux.push('/login'));
      }
      const data =yield call(transferlists,{origin_org_code:newsObject[1].orgs[0][2].code});
      if (data.data.code == 200) {
        yield put({
          type: 'success',
          payload:{
            Lists:data.data.ret
          }
        });
        if (data.data.ret.length < 1) {
          Toast.fail("没有数据", 1);
        }
      }
      else {
        Toast.success('查询失败！', 1);
      }
    },
  },

  reducers: {
    success(state, action){
      return {...state, ...action.payload};
    }
  }
};
